<!DOCTYPE html>
<html class="x-admin-sm">
    {include file="Admin/Public/head" title="文章列表" /}
    <link href="/static/admin/lib/wangeditor5.0.0/css/style.css" rel="stylesheet">
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="id"value="{$data['id']}">
                    <input type="hidden" name="content_type" value="0">
                  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>分类</label>
                        <div class="layui-input-inline">
                            <select name="navs_id" lay-filter="navs_id" lay-search>
                                {volist name="navs" id="val"}
                                <option value="{$val['id']}" {if $data['navs_id'] == $val['id']}selected{/if}>{$val['name']}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>标题
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" value="{$data['name']}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            关键词
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="keywords" value="{$data['keywords']}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            描述
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="description" value="{$data['description']}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>是否显示</label>
                        <div class="layui-input-inline">
                            <select name="display">
                                <option value="0" {if $data['display'] == 0}selected{/if}>显示</option>
                                <option value="1" {if $data['display'] == 1}selected{/if}>隐藏</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="desc" class="layui-form-label">
                            <span class="x-red">*</span>详细内容
                        </label>
                        <div class="layui-input-block">
                            <div id="toolbar-container"></div>
                            <div id="editor-container" style="height: 300px;">
                            </div>
                            <textarea hidden id="content" name="content">{$data['content']|raw}</textarea>
                        </div>
                    </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script src="/static/admin/lib/wangeditor5.0.0/js/index.min.js"></script>
        <script>
            var E = window.wangEditor; // 全局变量
            var html = document.getElementById('content').value;
            window.editor = E.createEditor({
                html: html,
                selector: '#editor-container',
                config: {
                    placeholder: '文章内容',
                    MENU_CONF: {
                        uploadImage: {
                            server: '/admin/upload',
                            fieldName: 'file',
                            onFailed(file, res) {
                                layer.msg(res.message);
                            },
                        },
                    },
                    onChange(editor) {
                        const html = editor.getHtml()
                        document.getElementById('content').value = html
                    }
                }
            })

            window.toolbar = E.createToolbar({
                editor,
                selector: '#toolbar-container',
                config: {}
            })
        </script>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //监听提交
                form.on('submit(add)', function(data) {
                    layer.load(2);
                    $.post("/admin/article/create", data.field, function(data){
                        layer.closeAll();
                        if (data.code == 200) {
                            layer.msg(data.msg, {time: 1500}, function(){
                                xadmin.close();
                                xadmin.father_reload();
                            })
                        } else if (data.code) {
                            layer.msg(data.msg)
                        }
                    })
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>
